//
//  ProjectileNode.m
//  iFly
//
//  Created by User-10 on 12/7/14.
//  Copyright (c) 2014 TeamDifferent. All rights reserved.
//

#import "ProjectileNode.h"
#import "Constants.h"
#import "SoundHandler.h"

@implementation ProjectileNode

+(instancetype)projectileWithImageNamed:(NSString*)image andPosition:(CGPoint)position andDamage:(NSInteger)damage {
    
    
    ProjectileNode* projectile = [self spriteNodeWithImageNamed:image];
    [projectile setupPhysicsBody];
    projectile.position = position;
    projectile.damage = damage;
    
    return projectile;
}

- (void) setupPhysicsBody {
    self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size];
    self.physicsBody.affectedByGravity = NO;
    self.physicsBody.categoryBitMask = weaponsCategory;
    self.physicsBody.collisionBitMask = 0;
    self.physicsBody.contactTestBitMask = obstacleCategory;
    self.name = @"projectile";
    self.physicsBody.usesPreciseCollisionDetection = YES;
}

-(void) shoot {
    [[SoundHandler sharedSoundPlayer] playSoundWithName:fireSound andType:@"caf"];
}

-(void) didHit {
    [self removeFromParent];
}

@end
